import {ref,onMounted,watch} from "vue";
import {useRoute} from "vue-router";
import {getCategoryAPI} from "@/apis/category.js";
export const useCategory= ()=>{
    const categoryData= ref({})
    const route = useRoute()
    const getCategory = async (id=route.params.id)=>{
        const res =await getCategoryAPI(id)
        categoryData.value = res.result
    }
    onMounted(()=>getCategory())
    watch(
        () => route.params.id,
        (newId) => {
            getCategory(newId);
        }, { immediate: true }
    )
    return {
        categoryData
    }
}